﻿using System.Web.Mvc;
using Model.Admin;
using Service.Admin;

namespace CMS.Areas.EasyUI.Controllers
{
    /// <summary>
    /// UserInfoController
    /// </summary>
    public class UserInfoController : BaseController
    {
        private readonly UserInfoService _userinfoservice;

        /// <summary>
        /// UserInfoController
        /// </summary>
        public UserInfoController(UserInfoService userinfoservice)
        {
            _userinfoservice = userinfoservice;
        }

        /// <summary>
        /// 管理权限
        /// </summary>
        /// <returns></returns>
        public ActionResult ManagerUser()
        {
            return View();
        }

        /// <summary>
        /// 管理权限
        /// </summary>
        [HttpPost]
        public JsonResult GetUserList()
        {
            var userlist = _userinfoservice.GetListByObject<UserInfo>(new { IsDelete = 0 });
            return new JsonResult() { Data = new { total = userlist.Count, rows = userlist }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

        /// <summary>
        /// DeleteUser
        /// </summary>
        /// <returns></returns>
        [HttpPost, ValidateAntiForgeryToken]
        public JsonResult OperateUser(UserInfo model, int flag)
        {
            switch (flag)
            {
                case 1:
                    model.IsDelete = 1;
                    break;
                case 3:
                    model.IsLock = 0;
                    break;
                case 4:
                    model.IsLock = 1;
                    break;
            }
            return Json(_userinfoservice.Update(model) ? new { code = 200, msg = "操作成功！" } : new { code = 401, msg = "操作失败！" });
        }
    }
}